package sz.com.postoffice.jxyzwgcase.service.impl;

import org.springframework.stereotype.Service;
import sz.com.postoffice.jxyzwgcase.dao.master.IDataSynchronizationDao;
import sz.com.postoffice.jxyzwgcase.service.IDataSynchronizationService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Service
public class DataSynchronizationService implements IDataSynchronizationService {


	@Resource
	private IDataSynchronizationDao dataSynchronizationDao;

	@Override
	public void dataSynchronization(Map map) {

		String tableName=(String)map.get("tableName");
		String period=(String)map.get("period");
		String del=(String)map.get("del");
		if(null!=tableName) {
			List<Map> resultList=(List<Map>) map.get("datas");
			if(tableName.equals("dm_customer_month_revenue_t")) {

				dataSynchronizationDao.delCustomerMonthRevenue(period);

				if(del.equals("1")) {
					dataSynchronizationDao.insertCustomerMonthRevenue(resultList);
				}
			}else if(tableName.equals("dm_delivery_month_t")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delDeliveryMonth(period);
				}
				dataSynchronizationDao.insertDeliveryMonth(resultList);
			}else if(tableName.equals("dm_emp_month_collection_t")) {

				if(del.equals("1")) {
					dataSynchronizationDao.delEmpMonthCollection(period);
				}
				dataSynchronizationDao.insertEmpMonthCollection(resultList);
			}else if(tableName.equals("dm_jxyz_emp_info_t")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delJxyzEmpInfo(period);
				}
				dataSynchronizationDao.insertJxyzEmpInfo(resultList);
			}else if(tableName.equals("dm_jxyz_sectin_info_t")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delJxyzSectinInfo(period);
				}
				dataSynchronizationDao.insertJxyzSectinInfo(resultList);
			}else if(tableName.equals("dm_regional_month_collection_t")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delRegionalMonthCollection(period);
				}
				dataSynchronizationDao.insertRegionalMonthCollection(resultList);
			}else if(tableName.equals("dm_sales_department_collection_month_t")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delSalesDepartmentCollectionMonth(period);
				}
				dataSynchronizationDao.insertSalesDepartmentCollectionMonth(resultList);
			}else if(tableName.equals("dwr_customer_daily_revenue_t")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delCustomerDailyRevenue(period);
				}
				dataSynchronizationDao.insertCustomerDailyRevenue(resultList);
			}else if(tableName.equals("dwr_delivery_detail_t")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delDeliveryDetail(period);
				}
				dataSynchronizationDao.insertDeliveryDetail(resultList);
			}else if(tableName.equals("dwr_emp_daily_collection_t")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delEmpDailyCollection(period);
				}
				dataSynchronizationDao.insertEmpDailyCollection(resultList);
			}else if(tableName.equals("dwr_jxyz_customer_relation_d")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delJxyzCustomerRelation(period);
				}
				dataSynchronizationDao.insertJxyzCustomerRelation(resultList);
			}else if(tableName.equals("dwr_jxyz_department_d")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delJxyzDepartment(period);
				}
				dataSynchronizationDao.insertJxyzDepartment(resultList);
			}else if(tableName.equals("dwr_jxyz_emp_d")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delJxyzEmp(period);
				}
				dataSynchronizationDao.insertJxyzEmp(resultList);
			}else if(tableName.equals("dwr_jxyz_resources_d")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delJxyzResources(period);
				}
				dataSynchronizationDao.insertJxyzResources(resultList);
			}else if(tableName.equals("dwr_regional_daily_collection_t")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delRegionalDailyCollection(period);
				}
				dataSynchronizationDao.insertRegionalDailyCollection(resultList);
			}else if(tableName.equals("dwr_sales_department_collection_t")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delSalesDepartmentCollection(period);
				}
				dataSynchronizationDao.insertSalesDepartmentCollection(resultList);
			}else if(tableName.equals("dwr_jxyz_customer_d")) {
				if(del.equals("1")) {
					dataSynchronizationDao.delJxyzCustomer(period);
				}
				dataSynchronizationDao.insertJxyzCustomer(resultList);
			}else if(tableName.indexOf("sdi_jxyz_pkp_waybill_base")>-1) {
				if(del.equals("1")) {
					dataSynchronizationDao.delWaybillbaseMapList(tableName);
				}
				String tables[]=tableName.split("_");
				String table=tables[tables.length-1];
				dataSynchronizationDao.insertWaybillbaseMapList(resultList,table);
			}

		}


	}



}
